import axios from 'axios'
import { message } from 'antd'

const request = axios.create({
  timeout: 600000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 请求前拦截
request.interceptors.request.use(
  (req) => {
    return req
  },
  (err) => {
    return Promise.reject(err)
  }
)

// 返回后拦截
request.interceptors.response.use(
  (response) => {
    const { data } = response
    if (data) {
      return Promise.resolve(data)
    }
    return Promise.reject(response)
  },
  (err) => {
    message.destroy()
    message.error('请求失败')
    return Promise.reject(err)
  }
)

export default request
